package br.edu.ufcg.splab.parser;

import br.edu.ufcg.splab.core.InterfaceEdge;
import br.edu.ufcg.splab.core.InterfaceGraph;
import br.edu.ufcg.splab.exceptions.LTSBTException;

public class CompareParsers {
	
	/**
	 * Compare the annotated graphs from the conversions of the graph.
	 * @param oldGraph The graph for conversion. 
	 * @return The annotated graph.
	 * @throws LTSBTException
	 */
	public InterfaceGraph compareGraphContraction(InterfaceGraph oldGraph) throws LTSBTException{		
		
		GraphToAnnotatedGraphParser parser1 = new GraphToAnnotatedGraphParser();
		InterfaceGraph annotatedGraph1 = parser1.graphContraction(oldGraph);
				
		ParserShortAnnotated parser2 = new ParserShortAnnotated();
		InterfaceGraph annotatedGraph2 = parser2.graphContraction(oldGraph);
		
		for(InterfaceEdge edge: annotatedGraph1.getEdges()){
			if(!annotatedGraph2.containsEdge(edge)){
				throw new LTSBTException("Invalid graphs: the parsers return different  annotated graphs.");
			}
		}	
		for(InterfaceEdge edge: annotatedGraph2.getEdges()){
			if(!annotatedGraph1.containsEdge(edge)){
				throw new LTSBTException("Invalid graphs: the parsers return different  annotated graphs.");
			}
		}	
		
		if(annotatedGraph1.getEdges().size() != annotatedGraph2.getEdges().size()){
			throw new LTSBTException("Invalid graphs: the parsers return different  annotated graphs.");
		}
		if(annotatedGraph1.getStates().keySet().size() != annotatedGraph2.getStates().keySet().size()){
			throw new LTSBTException("Invalid graphs: the parsers return different  annotated graphs.");
		}
		
		return annotatedGraph1;
	}

}
